"use strict";
cc._RF.push(module, '3024d6wxGBFTJr9QCZHCLmd', 'levelAvoidBase');
// scripts/modes/normalMode/levelAvoid/levelAvoidBase.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameConfig_1 = require("../../../engines/configs/gameConfig");
var gameEngine_1 = require("../../../engines/gameEngine");
var userInterface_1 = require("../../../engines/services/userContent/userInterface");
var LevelBase_1 = require("../../../Game/Base/LevelBase");
var Enum_1 = require("../../../Game/Enum");
var MainRoot_1 = require("../../../Game/MainRoot");
var levelAvoidEnemy_1 = require("./base/levelAvoidEnemy");
var ScheduleCom_1 = require("./base/ScheduleCom");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var levelAvoidBase = /** @class */ (function (_super) {
    __extends(levelAvoidBase, _super);
    function levelAvoidBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.player = null;
        _this.touchnode = null;
        _this.moveGroup = null;
        _this.moveSpeed = 2;
        _this.lab_time = null;
        _this.time = 0;
        _this.node_qiong = null;
        _this.com = null;
        _this.openTips = false;
        _this.startGame = false;
        _this.touchStartPos = null;
        _this.playerStartPos = null;
        _this.isPause = false;
        _this.playStopMove = false;
        return _this;
    }
    levelAvoidBase.prototype.onLoad = function () {
        _super.prototype.onLoad.call(this);
        this.touchnode.on(cc.Node.EventType.TOUCH_START, this.touchStart, this);
        this.touchnode.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
        this.touchnode.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
        this.touchnode.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
        this.lab_time.string = Math.ceil(this.time) + "s";
        this.com = new ScheduleCom_1.ScheduleCom();
    };
    levelAvoidBase.prototype.update = function (dt) {
        if (!this.startGame)
            return;
        if (this.openTips)
            return;
        if (this.isPause && this.playStopMove)
            return;
        this.time -= dt;
        if (this.time <= 0) {
            this.time = 0;
            this.startGame = false;
            this.gamePause(true);
            this.Win();
        }
        this.lab_time.string = Math.ceil(this.time) + "s";
        this.com.update(dt);
    };
    levelAvoidBase.prototype.OnTips = function () {
        var _this = this;
        cc.audioEngine.pauseAll();
        // super.OnTips()
        this.openTips = true;
        var rewardFun = null;
        // console.error(this.levelInfo.reward);
        if (this.levelInfo.reward) {
            rewardFun = function () {
                console.warn("!!!没有");
                if (!MainRoot_1.default.GotTips) {
                    gameEngine_1.services().userSrv.setPower(gameConfig_1.default.ADD_ONCE_POWER, true, true);
                    gameEngine_1.modules().uiControlModule.showGetRewarded(userInterface_1.REWARD_TYPE.POWER, gameConfig_1.default.ADD_ONCE_POWER);
                }
            };
        }
        var tipsPrams = {
            mode: this.m_mode,
            tips: this.tips,
            onReward: rewardFun,
            onClose: function () {
                _this.openTips = false;
                cc.audioEngine.resumeAll();
            }
        };
        MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.TIPSPAGE, tipsPrams);
    };
    levelAvoidBase.prototype.setGameStart = function () {
        this.startGame = true;
    };
    levelAvoidBase.prototype.touchStart = function (event) {
        if (!this.startGame)
            this.setGameStart();
        if (this.isPause && this.playStopMove)
            return;
        this.touchStartPos = this.player.parent.convertToNodeSpaceAR(event.getLocation());
        this.playerStartPos = this.player.getPosition();
    };
    levelAvoidBase.prototype.touchMove = function (event) {
        if (this.isPause && this.playStopMove)
            return;
        var touchpos = this.player.parent.convertToNodeSpaceAR(event.getLocation());
        var pos = this.playerStartPos.add(touchpos.sub(this.touchStartPos).normalize().mul(touchpos.sub(this.touchStartPos).mag() * this.moveSpeed));
        if (Math.abs(pos.x) > ((this.moveGroup.width / 2) - (this.player.width / 2) * this.player.scaleX)) {
            pos.x = (pos.x / Math.abs(pos.x)) * ((this.moveGroup.width / 2) - (this.player.width / 2) * this.player.scaleX);
        }
        if (Math.abs(pos.y) > (this.moveGroup.height / 2) - (this.player.height / 2) * this.player.scaleY) {
            pos.y = (pos.y / Math.abs(pos.y)) * ((this.moveGroup.height / 2) - (this.player.height / 2) * this.player.scaleY);
        }
        this.touchStartPos = touchpos;
        this.playerStartPos = pos;
        this.player.setPosition(pos);
    };
    levelAvoidBase.prototype.touchEnd = function (event) {
        if (this.isPause && this.playStopMove)
            return;
        this.touchStartPos = null;
        this.playerStartPos = null;
    };
    /**设置游戏暂停 */
    levelAvoidBase.prototype.gamePause = function (bool) {
        this.isPause = bool;
        this.playStopMove = bool;
    };
    levelAvoidBase.prototype.scheduleOn = function (call, time) {
        // let dttime = 0
        // let func = () => {
        //     if (this.isPause) return
        //     if (this.openTips) return
        //     dttime += cc.director.getDeltaTime()
        //     if (dttime >= time) {
        //         this.unschedule(func)
        //         call()
        //     }
        // }
        // this.schedule(func)
        this.com.add(call, time, 1);
    };
    levelAvoidBase.prototype.scheduleAny = function (call, time) {
        // let dttime = 0
        // let func = () => {
        //     if (this.isPause) return
        //     if (this.openTips) return
        //     dttime += cc.director.getDeltaTime()
        //     if (dttime >= time) {
        //         dttime = 0;
        //         call()
        //     }
        // }
        // this.schedule(func)
        if (time === void 0) { time = 0; }
        return this.com.add(call, time);
    };
    levelAvoidBase.prototype.newLabNode = function (colorHEX) {
        if (colorHEX === void 0) { colorHEX = "#e4664f"; }
        var node = cc.instantiate(this.node_qiong.node);
        node.parent = this.node_qiong.node.parent;
        node.getComponent(levelAvoidEnemy_1.default).lab.node.color = new cc.Color().fromHEX(colorHEX);
        return node.getComponent(levelAvoidEnemy_1.default);
    };
    __decorate([
        property({ type: cc.Node, displayName: "操作目标" })
    ], levelAvoidBase.prototype, "player", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "操作界面" })
    ], levelAvoidBase.prototype, "touchnode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "移动范围" })
    ], levelAvoidBase.prototype, "moveGroup", void 0);
    __decorate([
        property({ displayName: "移动速度" })
    ], levelAvoidBase.prototype, "moveSpeed", void 0);
    __decorate([
        property({ type: cc.Label, displayName: "倒计时lab" })
    ], levelAvoidBase.prototype, "lab_time", void 0);
    __decorate([
        property({ displayName: "倒计时" })
    ], levelAvoidBase.prototype, "time", void 0);
    __decorate([
        property({ type: levelAvoidEnemy_1.default, displayName: "穷" })
    ], levelAvoidBase.prototype, "node_qiong", void 0);
    levelAvoidBase = __decorate([
        ccclass
    ], levelAvoidBase);
    return levelAvoidBase;
}(LevelBase_1.default));
exports.default = levelAvoidBase;

cc._RF.pop();